package com.huawei.appgallery.share.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.share.protocol.WBEntryActivityProtocol;
import com.huawei.appgallery.share.protocol.WBEntryActivityProtocol.Request;
import com.huawei.appmarket.support.emui.permission.BasePermissionActivity;
import com.sina.weibo.sdk.WbSdk;
import com.sina.weibo.sdk.api.ImageObject;
import com.sina.weibo.sdk.api.TextObject;
import com.sina.weibo.sdk.api.WeiboMultiMessage;
import com.sina.weibo.sdk.auth.AuthInfo;
import com.sina.weibo.sdk.share.WbShareCallback;
import com.sina.weibo.sdk.share.WbShareHandler;
import o.cfw;
import o.cvt;
import o.cwj.i;
import o.cwr;
import o.cws;
import o.cxd;
import o.cxo;
import o.dge.d;
import o.dgh;
import o.dgm;
import o.dgu;
import o.diu;
import o.Logger;
import o.ContentManager;
import o.evd;

public class WBEntryActivity extends BasePermissionActivity<WBEntryActivityProtocol> implements WbShareCallback {
    private cws ʻॱ = null;
    private String ˊॱ;
    private String ˏॱ;
    private WbShareHandler ͺ = null;
    private String ॱˊ;
    private byte[] ᐝॱ;

    class e extends cxd {
        final /* synthetic */ WBEntryActivity ॱ;

        private e(WBEntryActivity wBEntryActivity) {
            this.ॱ = wBEntryActivity;
        }

        public void ˎ(Context context, String str, String str2) {
            this.ॱ.ˏॱ = str2;
            if (this.ॱ.ॱˊ()) {
                this.ॱ.ˊॱ();
            }
        }
    }

    public void ʼ() {
        getWindow().requestFeature(1);
        evd.ˏ(getWindow());
    }

    public void ॱॱ() {
        if (diu.ˊ().ˎ()) {
            ᐝ();
        } else {
            finish();
        }
    }

    private void ᐝ() {
        WBEntryActivityProtocol wBEntryActivityProtocol = (WBEntryActivityProtocol) ʾ();
        if (wBEntryActivityProtocol == null) {
            finish();
            return;
        }
        Request ˊ = wBEntryActivityProtocol.ˊ();
        if (ˊ == null) {
            finish();
            return;
        }
        this.ॱˊ = ˊ.ˏ();
        this.ˊॱ = ˊ.ˊ();
        this.ᐝॱ = ˊ.ˋ();
        cxo.ˎ(getString(i.ˏॱ), this, new e());
    }

    private boolean ॱˊ() {
        if (this.ͺ != null) {
            cwr.ॱ.ˎ("WBEntryActivity", "weibo api has inited.");
            return true;
        } else if (this.ˏॱ != null) {
            WbSdk.install(this, new AuthInfo(this, this.ˏॱ, getString(i.ˊॱ), "email,direct_messages_read,direct_messages_write,friendships_groups_read,friendships_groups_write,statuses_to_me_read,follow_app_official_microblog,invitation_write"));
            this.ͺ = new WbShareHandler(this);
            this.ͺ.registerApp();
            cwr.ॱ.ˋ("WBEntryActivity", "init weibo api !");
            return true;
        } else {
            cwr.ॱ.ˊ("WBEntryActivity", "weibo AppKey is null.");
            return false;
        }
    }

    private void ˊॱ() {
        WeiboMultiMessage weiboMultiMessage = new WeiboMultiMessage();
        TextObject textObject = new TextObject();
        textObject.text = this.ˊॱ;
        weiboMultiMessage.textObject = textObject;
        ImageObject imageObject = new ImageObject();
        imageObject.imageData = this.ᐝॱ;
        weiboMultiMessage.imageObject = imageObject;
        ˏ(weiboMultiMessage);
    }

    private void ˏ(WeiboMultiMessage weiboMultiMessage) {
        if (this.ͺ != null) {
            try {
                this.ͺ.shareMessage(weiboMultiMessage, true);
                return;
            } catch (Throwable e) {
                cwr.ॱ.ˊ("WBEntryActivity", "error when share to sina weibo.", e);
                return;
            }
        }
        cwr.ॱ.ˊ("WBEntryActivity", "mWeiboShareAPI is null.");
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                int i3 = extras.getInt("_weibo_resp_errcode", -1);
                if (Logger.ˎ()) {
                    cwr.ॱ.ˎ("WBEntryActivity", "onActivityResult errorCode: " + i3);
                }
                switch (i3) {
                    case 0:
                        onWbShareSuccess();
                        return;
                    case 1:
                        onWbShareCancel();
                        return;
                    case 2:
                        cwr.ॱ.ˋ("WBEntryActivity", "share weibo failed: " + extras.getInt("_weibo_resp_errstr"));
                        onWbShareFail();
                        return;
                    default:
                        finish();
                        return;
                }
            }
            cwr.ॱ.ˎ("WBEntryActivity", "onActivityResult bundle is null.");
            finish();
            return;
        }
        cwr.ॱ.ˎ("WBEntryActivity", "onActivityResult intent is null.");
        finish();
    }

    public void onWbShareSuccess() {
        String userId = UserSession.getInstance().getUserId();
        dgh.onEvent(new d(ContentManager.getInstant().getContext(), i.ˎ).ˏ("03|00|" + userId + '|' + this.ॱˊ).ˋ());
        cvt ˋ = dgu.ˋ("8", this.ॱˊ, dgm.ˎ((Activity) this));
        ˋ.ˊ("WEIBO");
        this.ʻॱ = new cws(this);
        cfw.ˎ(ˋ, this.ʻॱ);
    }

    public void onWbShareCancel() {
        finish();
    }

    public void onWbShareFail() {
        finish();
    }

    public void finish() {
        if (this.ʻॱ != null) {
            this.ʻॱ.ˏ();
        }
        super.finish();
    }

    public boolean ॱᐝ() {
        return false;
    }
}
